package com.atmc.controller;

import com.atmc.entity.*;
import com.atmc.mapper.ArtImagesMapper;
import com.atmc.mapper.HeadPotraitMapper;
import com.atmc.service.AcomentNumService;
import com.atmc.service.ArtLikerService;
import com.atmc.service.ArticleService;
import com.atmc.service.UserService;
import io.minio.*;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * @BelongsProject: SpringCloud1216
 * @BelongsPackage: com.atmc.controller
 * @Author: chuyings
 * @CreateTime: 2022-11-11  13:33
 * @Version: 1.0
 */
@RestController
@CrossOrigin
public class ArticleController {
    @Autowired
    ArtLikerService artLikerService;
    @Autowired
    UserService userService;
    @Autowired
    HeadPotraitMapper headPotraitMapper;
    @Autowired
    ArticleService articleService;
    @Autowired
    @Qualifier("minioClient")
    MinioClient minioClient;
    @Value("${minio.bucketName}")
    private String bucketName;
    @Autowired
    ArtImagesMapper artImagesMapper;
    @Autowired
    AcomentNumService acomentNumService;
    //返回帖子所有信息
    @PostMapping("/getArticleAll")
    public ResponseResult getArticleAll(){
        ResponseResult articleAll = articleService.getArticleAll();
        return articleAll;
    }
    //发布帖子
    @PostMapping("/publishPost")
    public ResponseResult publishPost(@RequestParam("context") String context,@RequestParam("userName")String userName,@RequestParam(required = false ,value="artPhoto") List<MultipartFile> artPhoto){
        return  articleService.publishPost(context,userName,artPhoto);
    }
    //回复评论
    @PostMapping("/commentPost")
    public ResponseResult commentPost(@RequestBody Article articleOne){

        return articleService.commentPost(articleOne);
    }
    //点赞功能
    @PostMapping("/requestLiker")
    public ResponseResult requestLiker(@RequestBody ArtLiker artLiker){

        return artLikerService.requestLiker(artLiker.getArticleId(),artLiker.getUserName());
    }
    //搜索用户查询帖子信息
    @PostMapping("/selectArticle")
    public List<Article> selectByUserName(@RequestBody DetailUser detailUser){
        return articleService.selectByUserName(detailUser.getUserName());
    }

    //我的点赞对应的帖子信息
    @PostMapping("/myLikerArticle")
    public ResponseResult myLikerArticle(@RequestBody ArticleLikerList likers){

        return articleService.myLikerArticle(likers.getLikers());
    }

}
